<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>细项管理</title>
	<base href="<%=basePath %>"/>
	<link rel="stylesheet" href="assets/css/bootstrap.css"/>
	<script src="assets/js/jquery.min.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
</head>
<body>
	<form id="detailForm" action="detail/findItemdetails.action" method="post">

		<div class="container">
			<div class="col-lg-10 col-lg-offset-1">
				<div class="panel-body">
					<input type="text" name="detailName" id="detailName" placeholder="细项名" style="width:250px" class="input-text" value="${param.detailName}">
					<input type="hidden" name="pageSize" value="5">
					<input type="hidden" name="pageNum" value="1">
					<input type="hidden" id="itemId" name="itemId" value="${param.itemId}">
					<button name="check" class="btn btn-primary" type="submit" >搜索</button>
				</div>
				<table id="itemTable" class="table table-hover table-bordered">
					<thead>
					<tr class="text-c">
						<th width="80">编号</th>
						<th width="100">名称</th>
						<th width="100">单位</th>
						<th width="100">最低指标</th>
						<th width="100">最高指标</th>
						<th width="100">操作</th>
					</tr>
					</thead>
					<tbody id="detailTbody">
					<c:forEach items="${DetailPage.list}" var="detail">
						<tr>
							<td>${detail.detailId}</td>
							<td>${detail.detailName}</td>
							<td>${detail.unit}</td>
							<td>${detail.min}</td>
							<td>${detail.max}</td>
							<td class="f-14 "><a class="btn-sm btn-primary" data-toggle='modal' data-target='#detail_edit' title="编辑" onclick="detail_show(this)" >编辑</a>
								<a  class="btn-sm btn-danger" title="删除"  href="javascript:;" onclick="delDetail(${detail.detailId},${detail.itemId})" class="ml-5" style="text-decoration:none">删除</a></td>
						</tr>
					</c:forEach>
					</tbody>
				</table>
				<a data-toggle='modal' data-target='#add_item' onclick="detail_add('添加细项','detail_add.action?itemId=${param.itemId}','','330')" class="btn-sm btn-primary radius">添加细项</a>
				<div id="page" style="float: right">
					总共${DetailPage.pages}页，当前第${DetailPage.pageNum}页，一页${DetailPage.size}行，总共${DetailPage.total}行。
					<a class="btn-sm btn-primary" onclick="pre_page(${DetailPage.prePage})">上一页</a>
					<a class="btn-sm btn-primary" onclick="pre_page(${DetailPage.nextPage})">下一页</a>
				</div>
			</div>
		</div>
	</form>

	<div class="modal fade" id="detail_edit">
		<div class="modal-dialog" style="width: 600px">
			<div class="modal-content">
				<!-- 模态框头部 -->
				<form action="item/addItem.action" method="post" id="addItemFrom">
					<div class="modal-header" style="text-align: center">
						<label>修改细项</label>
						<button type="button" class="close" data-dismiss="modal">&times;</button>
					</div>
					<div class="modal-body" style="overflow:auto">
						<table>
							<tr>
								<td>编号：</td>
								<td><input type="text" class="input-text"  disabled="on" id="detailId" name="detailId"></td>
							</tr>
							<tr>
								<td>细项名：</td>
								<td><input type="text" class="input-text"  placeholder="细项名称" id="e_detailName" name="e_detailName"></td>
							</tr>
							<tr>
								<td>单位：</td>
								<td><input type="text" class="input-text"  placeholder="单位" id="unit" name="unit"></td>
							</tr>
							<tr>
								<td>最低指标：</td>
								<td><input type="text" class="input-text" placeholder="最低指标" id="min" name="min"></td>
							</tr>
							<tr>
								<td>最高指标：</td>
								<td><input type="text" class="input-text"  placeholder="最高指标" id="max" name="max"></td>
							</tr>
						</table>
					</div>
					<div class="modal-footer">
						<a class="btn-sm btn-primary" onclick="detail_edit()">提交</a>
					</div>
				</form>
			</div>
		</div>
	</div>


</div>
<script type="text/javascript" src="assets/H-ui/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="assets/H-ui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="assets/H-ui/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="assets/H-ui/static/h-ui.admin/js/H-ui.admin.page.js"></script>
<script type="text/javascript">


	function pre_page(num) {
	    if(num>0){
        console.log(num);
            var form=$("#detailForm");
            $("input[name='pageNum']").val(num);
            form.method="post";
            form.submit();}
    }

    function changPage(num) {
	    if(num>0){
        var form=$("form");
        $("input[name='pageNum']").val(num);
        form.method="post";
        form.submit();
        }
    }

    function detail_add(title,url,w,h){
        layer_show(title,url,w,h);
    }
	function detail_show(obj) {
        var tds= $(obj).parent().parent().find('td');
        $("#detailId").val(tds.eq(1).text())
        $("#e_detailName").val(tds.eq(2).text());
        $("#unit").val(tds.eq(3).text());
        $("#min").val(tds.eq(4).text());
        $("#max").val(tds.eq(5).text());
    }

    function detail_edit() {
        var url="detail/detail_edit.action";
        var detail={
            detailId:$("#detailId").val(),
            detailName:$("#e_detailName").val(),
            unit:$("#unit").val(),
            min:$("#min").val(),
            max:$("#max").val()
        }
        $.post(
            url,
            detail,
            function (msg) {
                if(msg="success"){
                    alert("修改成功！");
                    var itemId=$("#itemId").val();
                    location.href="${pageContext.request.contextPath}/detail/findItemdetails.action?itemId="+itemId;
                }else{
                    alert("添加失败！");
                }
            }, 'text'
        );
    }

    function delDetail(detailId,itemId) {
		location.href="detail/delDetail.action?detailId="+detailId+"&itemId="+itemId;
    }


</script>
</body>
</html>